<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!--<link href="../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">-->
		<link rel="stylesheet" type="text/css" href="../../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css"/>
		<!--<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />-->
		<link rel="stylesheet" type="text/css" href="../../../css/footer.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/commodity_details.css"/>
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
		
	</head>
	<body>
		<div id="wrap">
			<div id="main">
				<div id="header">
					<a id="headImg" href="javascript:history.go(-1)"><img class="headImg" src="../../../images/12.png" /></a>
					<p id="headTitle">商家详情页</p>
					<a id="headerPay" onclick="pay()"></a>
				</div>
				<div id="content">
					<div class="seller_wap">
						<div class="pic">
							<img id="shopDetailsPic" />
							<p id="sign">赠送消费额的100倍积分</p>
						</div>
						<div style="background-color: #FFF; padding: 10px 0;">
							<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" id="shopName"><b>店名：</b><span></span> 
								<a id="shouchang" style="position: absolute;right: 0; margin-top: 0.069444rem;margin-right: 0.277777rem;">收藏 
									<img src="../../../images/coalltion/weishouchang.pngi" style="width: 0.5rem; position: relative;top: -1px;" alt="" />
								</a>
							</p>
							<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" id="acticeName"><b>活动名称：</b><span></span></p>
							<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" id="add"><b>所在区域/地址：</b><span></span></p>
							<p style="margin-bottom: 10px; margin-top: 0.069444rem;margin-left: 0.277777rem;" id="shopTel"><b>电话: </b><a></a></p>
						</div>
						<h1 style="position: relative;">
							用户评价(<span id="assess">0</span>)  
						
						</h1>
						
					</div>
				</div>
			</div>
			<div id="foot" class="row">
			<a class="foot col-xs-3 col-sm-3" href="../../kaoqin/index2.html">
					<img class="footImg" src="../../../images/15.png" />
					<p>管理</p>
				</a>
			<a class="foot col-xs-3 col-sm-3" href="../colalition.html">
					<img class="footImg" src="../../../images/14.png" />
					<p>联盟</p>
				</a>
			<a class="foot col-xs-3 col-sm-3" href="../../store/store.html">
					<img class="footImg" src="../../../images/11.png" />
					<p>商城</p>
				</a>
			<a class="foot col-xs-3 col-sm-3" href="../../personage/personIndex.html">
					<img class="footImg" src="../../../images/13.png" />
					<p>我的</p>
				</a>
		</div>
		</div>

	</body>
	<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/handlebars-v2.0.0.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../../js/rhAdmin.js" type="text/javascript" charset="utf-8"></script>
	<script id="table_template1" type="text/x-handlebars-template">
      	{{#each list}}
      		<div class="pingjia">
				<img src="../../../images/coalltion/touxiang.png"/>
				<p>{{memberName}}</p>
				<span>{{assessDate}}</span>
			</div>
			<div class="pingjia_main">
				<p>{{assessContent}}</p>
				<p><span style="color: #E83023;">商家回复: </span>{{assessReplyContent}}</p>
			</div>
    	{{/each}}
    </script>
	<script src="../../../js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var shopId = "";
		$(function(){
			//获取get值
			function GetQueryString(name){
    			 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     			 var r = window.location.search.substr(1).match(reg);
    			 if(r!=null)return  unescape(r[2]); return null;
			}
			shopId = GetQueryString("shopId")
			var test = window.location.href;
			if(test.indexOf("shopId=")>-1){ 
				shopId = test.split("?")[1].split("=")[1];
			} 
			if(shopId == ""){
				alert("获取商品时失败，请联系系统管理员！");
			}
			if(!$.cookie('tokenRh')){
				al("您还未登录，请登录后再试");
			}
			//var shopId = test.split("?")[1].split("=")[1];
			//获取商户详细信息
			$.ajax({
				type:"GET",
				url:"http://47.104.13.109/mall-service/shop/search?shopId="+shopId,
				async:true,
				success:function(data){
					console.log(data)
					if(data != null){
						document.getElementById('shopDetailsPic').src = data.shopDetailsPic;
						document.getElementById('sign').innerHTML = data.shopSign;
						$("#shopName span").html(data.shopName);
						$("#acticeName span").html(data.shopSign);
						$("#add span").html(data.shopAdd);
						var phone = data.shopPhone || "暂无";
						if (phone == "暂无") {
							phone = 'javascript:void(0);'
							$("#shopTel a").html('暂无');
							$("#shopTel a").attr('href',phone);
						}else{
							phone = 'tel:'+ phone 
							$("#shopTel a").html(data.shopPhone);
							$("#shopTel a").attr('href',phone);
						}
						
					}
					
				}
			});
			//查询是否收藏
		$.ajax({
			type: "get",
			url: "http://47.104.13.109/member-service/member/client/collect/check",
			async: true,
			data: {
				shop_id: shopId,
				token: $.cookie('tokenRh')
			},
			success: function(bol) {
				if(bol) {
					$("#shouchang img").attr('src', '../../../images/coalltion/shouchang.png');
				} else {
					$("#shouchang img").attr('src', '../../../images/coalltion/weishouchang.png');
				}
			},
			error: function(error) {
				alert("收藏查询时错误");
			}
		});
		$("#shouchang").click(function() {
			$.ajax({
				type: "get",
				url: "http://47.104.13.109/member-service/member/client/collect/check",
				async: true,
				data: {
					shop_id: shopId,
					token: $.cookie('tokenRh')
				},
				success: function(bol) {
					if(bol) {
						//删除收藏
						$.ajax({
							type: "delete",
							url: 'http://47.104.13.109/member-service/member/mine/collect/' + shopId + '?token=' + $.cookie("tokenRh"),
							async: true,
							success: function(res) {
								console.log(res);
								
									$("#shouchang img").attr('src', '../../../images/coalltion/weishouchang.png');
								
							},
							error: function(error) {
								alert("收藏删除时出现错误，请联系系统管理员");
							}
						});
					} else {
						//添加收藏
						$.ajax({
							type: "post",
							url: 'http://47.104.13.109/member-service/member/mine/collect/' + shopId + '?token=' + $.cookie("tokenRh"),
							async: true,
							success: function(res1) {
								console.log(res1);
								if(res1) {
									$("#shouchang img").attr('src', '../../../images/coalltion/shouchang.png');
								}
							},
							error: function(error) {
								alert("添加收藏时出现错误，请联系系统管理员");
							}
						});
					}
				},
				error: function(error) {
					alert("查询商品收藏时出现错误，请联系系统管理员");
				}
			});

		})
		//查询是否收藏
		$.ajax({
			type: "get",
			url: "http://47.104.13.109/member-service/member/client/collect/check",
			async: true,
			data: {
				shop_id: shopId,
				token: $.cookie('tokenRh')
			},
			success: function(bol) {
				console.log(bol)
				if(bol) {
					$("#shouchang img").attr('src', '../../../images/coalltion/shouchang.png');
				} else {
					$("#shouchang img").attr('src', '../../../images/coalltion/weishouchang.png');
				}
			},
			error: function(error) {
				alert("查询收藏时出现错误，请联系系统管理员");
			}
		});	
			
			//获取商户的评价列表
			$.ajax({
				type:"GET",
				url:"http://47.104.13.109/mall-service/assess/list",
				async:true,
				data:{
//					"goodsId":null,
					"shopId":shopId,
					"pageNum":"1",
					"pageSize":"10"
				},
				success:function(data){
					console.log(data)
					document.getElementById('assess').innerHTML = data.size;
//					console.log(data);
					var myTemplate1 = Handlebars.compile($("#table_template1").html());
					$('.seller_wap').append(myTemplate1(data));
				}
			});
		})
		function pay(){
				//登陆判断
				var tokenRezt = $.cookie("tokenRh");
				if(!tokenRezt) {
				window.location.href = "../../login/login/login.html";
				}
				if(shopId != ""){
					window.location.href = "../commodity_pay/foods_pay.html?shopId="+shopId;					
				}	
			}
		

	</script>
</html>